#include "config.h"

#include "sr.h"

#ifdef ECM_MTRACE

sr_t *
get_sr_mtraces(void)
{
	sr_t		*sr_traces = NULL, *sr_trace, *sr_callers;
	ecm_ptrs_t	*mtraces;
	ecm_mtrace_t	*mtrace;
	unsigned	i, j;

	if ((mtraces = ecm_get_mtraces()) == NULL)
		return NULL;

	sr_traces = sr_create_dir();
	
	for (i = 0; i < mtraces->len; i++) {
		sr_trace = sr_create_dir();
		mtrace = mtraces->pdata[i];
		sr_append(sr_trace, sr_create_str(ST_STR, mtrace->meminfo));
		sr_callers = sr_append(sr_trace, sr_create_dir());
		for (j = 0; j < ECM_MTRACE_MAX_CALLERS && mtrace->callers[j]; j++)
			sr_append(sr_callers, sr_create_str(ST_STR, mtrace->callers[j]));
		sr_append(sr_traces, sr_trace);
	}
	ecm_clear_mtraces(mtraces);

	return sr_traces;
}

#endif
